//
//  WBMainViewController.swift
//  WB123
//
//  Created by xuyunde mac pro on 2017/6/29.
//  Copyright © 2017年 NSObjiect. All rights reserved.
//

import UIKit

class WBMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = WBTabBar()
        
        //设置代理
        tabBar.wbdelegate = self
        // 闭包实例化
        tabBar.closure = {
            //回调
            print("监听按钮点击")
        }
        
        setValue(tabBar, forKey: "tabBar")
        
        addChildViewController(childController: WBHomeViewController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(childController: WBMessageViewController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(childController: WBDiscoverViewController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(childController: WBProfileViewController(), title: "我", imgName: "tabbar_profile")
     
    }
    func addChildViewController(childController:UIViewController,title:String,imgName:String){
        childController.title = title
        
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: UIControlState.selected)
        
        childController.tabBarItem.image = UIImage(named: imgName)?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        childController.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        let nav = WBNavigationController(rootViewController:childController)
        
        addChildViewController(nav)
    }
}
extension WBMainViewController:WBTabBarDelegate{
    func composeButtonSelect() {
        print("按钮代理点击")
        WBComposeView.show(target: self)
    }
}
